(function(){
    "use strict";
    app.controller('instrumentCtrl', ['$rootScope', '$scope', 'httpLoad','$state',function($rootScope, $scope, httpLoad, $state) {
	 /* 变量声明
    ---------------------------------------*/
	 
	/* scope变量声明
    ---------------------------------------*/
	$rootScope.moduleTitle = '仪表盘';
    $rootScope.link = '/statics/css/common.css';//引入页面样式
    $scope.board={
    	container:{},
    	image:{},
    	net:{},
    	volume:{},
    	app:{},
    	host:{},
    	cluster:{}
    };

	/* UI事件绑定
    ---------------------------------------*/
    $scope.goList = goListFun;
	/* 入口函数 （代码执行的唯一入口，也是起始点，位置可以根据具体情况调整）
    ---------------------------------------*/
   (function () {
       _init();
   })();
   /* UI事件实现
   ---------------------------------------*/
   //跳转镜像\网络、硬盘、容器
   function goListFun(url){
       $state.go(url,{flag:'border'});
   }
   /* 内部方法实现
   ---------------------------------------*/
   function _init(){
	   _getAppImageInfo();
	   _getNetContVolInfo();
	   _getHostClusterImgInf();
   }
   //获得应用的数量和镜像的数量
   function _getAppImageInfo(envId){ 
	   httpLoad.loadData({
	        url: '/application/getApplicationStatisticalInfo.do',
	        method: 'GET',
	        data:{envId:envId},
	        success: function(rep){
	        	if(rep&&rep.success){
	        		$scope.board.app.running=rep.runningApplicationCounts;
		        	$scope.board.app.count=rep.applicationCounts;
		        	$scope.board.app.stop=rep.applicationCounts-rep.runningApplicationCounts;
		        	$scope.board.app.conf={
		        		colors:['#0099cc','#cccccc'],
		        		type:'pie',
		        		name:'占比',
		        		data:[
		        		    {name:'运行中',value:$scope.board.app.running},
		        		    {name:'停止中',value:$scope.board.app.stop}
		        		],
	   	        		radius:['50%','70%'],
	   	        		labelPos:'outside'
		        	};
		        	$scope.board.image.list=rep.last5ImageCount;
		        	$scope.board.app.list=rep.last5UpdateTime;
	        	}
	        	window.hideLoading();
	        }
	    });
   }
   //网络，卷和容器的数量
   function _getNetContVolInfo(){ 
	   httpLoad.loadData({
	        url: '/deployer/getContainerNetworkVolumeCounts.do',
	        method: 'GET',
	        noParam:true,
	        success: function(rep){
	            if(rep&&rep.success) {
	            	window.hideLoading();
	            	$scope.board.container.count=rep.ContainersCount;
	            	$scope.board.container.running=rep.runningContainersCount;
	            	$scope.board.container.stopping=rep.ContainersCount-rep.runningContainersCount;
	            	$scope.board.volume.count=rep.volumesCount;
	            	$scope.board.net.count=rep.networkCount;
	            	$scope.board.container.conf={
	            		colors:['#0099cc','#cccccc'],
    	        		type:'pie',
    	        		name:'占比',
    	        		data:[
    	        		    {name:'运行中',value:$scope.board.container.running},
    	        		    {name:'停止中',value:$scope.board.container.stopping}
    	        		],
       	        		radius:['50%','70%'],
       	        		labelPos:'outside'
    	        	};
	            }
	        }
	    });
   }
   //获取主机、集群、镜像信息
   function _getHostClusterImgInf(){
	   httpLoad.loadData({
	        url: '/runtime/board/all',
	        method: 'GET',
	        noParam:true,
	        success: function(rep){
	            if(rep) {
	            	window.hideLoading();
	            	$scope.board.cluster.list=rep.clusterboard.clusterArray;
	            	$scope.board.cluster.status=rep.clusterboard.clusterIshealthy;
	            	$scope.board.host.running=rep.hostboard.host_online;
	            	$scope.board.host.stopping=rep.hostboard.host_offline;
	            	$scope.board.host.count=rep.hostboard.host_total;
	            	$scope.board.image.count=rep.imageboard.all_image;
	            	$scope.board.image.private=rep.imageboard.private_image;
	            	$scope.board.image.public=rep.imageboard.public_image;
	            	$scope.board.host.conf={
	            		colors:['#0099cc','#cccccc'],
	   	        		type:'pie',
	   	        		name:'占比',
	   	        		data:[
	   	        		    {name:'使用中 ',value:$scope.board.host.running},
	   	        		    {name:'维护中',value:$scope.board.host.stopping}
	   	        		],
	   	        		radius:['30%','55%'],
	   	        		labelPos:'outside'
	   	        	};
	            }
	        }
	    });
   }
	
/*    httpLoad.loadData({
        url: '/instrument/detail',
        method: 'GET',
        noParam:true,
        success: function(data){
            if(data.success) {
                // $scope.datalist=data.data.data;
                // $scope.isDataLoad = true;
                // $scope.data0 = data.data.rows0;
                // $scope.name0 = data.data.name0;
                meterService.eCharts("depart0");
                meterService.eCharts("depart1");
                meterService.eCharts("depart2");
                meterService.eCharts("depart3");
            }
        }
    });*/

}]);
})();